import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

// !参数 1：模块名，叫啥无所谓，唯一就行
const useCounterStore = defineStore('counter', () => {
  // state
  const count = ref(1)
  // getters
  const doubleCount = computed(() => count.value * 2)
  // mutation
  const increment = () => {
    count.value++
  }
  // action
  const incrementAsync = () => {
    setTimeout(() => {
      increment()
    }, 1000)
  }
  // !不要忘记 return
  return { count, doubleCount, increment, incrementAsync }
})

export default useCounterStore